// File: src/bbs/gitee_sync.rs
use chrono::Local; //{Local, TimeZone}; // 添加 TimeZone 导入
//use crate::bbs::post::BbsPost;
use hex;
use crate::bbs::comment::BbsComment;

pub struct GiteeManualSync;

impl GiteeManualSync {

    //pub fn generate_template(post: &super::post::BbsPost) -> String {
    pub fn generate_template(
        title: &str, 
        url: &str,
	content_hash: &str, 
	author: &str
    ) -> String {
//        let dt = Local.timestamp_opt(post.timestamp, 0) //.unwrap_or_default();
//	    .single()
//            .unwrap_or_else(|| Local::now());
	let dt = Local::now();
        format!(
            "--- MOCHAIN BBS 提交模板(v2) ---\n\
            标题: {}\n\
            URL: {}\n\
            作者: {}\n\
            时间: {}\n\
            哈希: {}\n\
            --------------------------",
            title,
            url,
            author,
            dt.format("%Y-%m-%d %H:%M:%S"),
            content_hash	    
        )
    }

//    pub fn parse_template(template: &str) -> Option<BbsPost> {
//        // 实现模板解析逻辑
//    }
    pub fn generate_comment_template(comment: &BbsComment) -> String {
        format!(
            "--- MOCHAIN 评论模板 ---\n\
            关联帖子哈希: {}\n\
            URL: {}\n\
            作者: {}\n\
            内容哈希: {}\n\
            ------------------------\n{}",
            comment.post_hash,
	    comment.url,
            comment.author,
            hex::encode(&comment.content_hash),
            comment.content
        )
    }
}

//fn calculate_content_hash(content: &str) -> String {
//    use sha2::{Sha256, Digest};
//    let mut hasher = Sha256::new();
//    hasher.update(content);
//    format!("{:x}", hasher.finalize())
//}
